package com.zzhua.cglib;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class CustomizedMethodInterceptor implements MethodInterceptor {

    /**
     * 生成的代理类：
     *      (Cat$$EnhancerByCGLIB$$f075d299.class)：
     *      var10000.intercept(this, CGLIB$sleep$0$Method, new Object[]{new Integer(var1)}, CGLIB$sleep$0$Proxy);
     *
     * @param obj           代理对象     com.zzhua.cglib.Cat$$EnhancerByCGLIB$$76d7298b@5f341870
     * @param method        被代理的方法  class com.zzhua.cglib.Cat
     * @param args          方法参数
     * @param methodProxy   方法代理
     *                          {
     *                              sig1: eat()V,
     *                              sig2：CGLIB$eat$1()V ,
     *                              createInfo:
     *                                  {
     *                                      c1:class com.zzhua.cglib.Cat,
     *                                      c2:class com.zzhua.cglib.Cat$$EnhancerByCGLIB$$76d7298b
     *                                  }
     *                          }
     * @return
     * @throws Throwable
     */
    @Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        System.out.println("before method run ...");
        Object result = methodProxy.invokeSuper(obj, args);
        System.out.println("after  method run ...");
        return result;
    }
}
